import os
import json
from typing import List, Dict

# 获取当前工作路径
PATH = os.getcwd()

def read_json() -> List[Dict]:
    """
    读取配置目录下的所有JSON文件，并将其内容以字典形式存储在列表中返回。

    Returns:
        List[Dict]: 包含所有JSON文件内容的列表，每个元素为一个字典。
    """
    config_file_list = [file_name for file_name in os.listdir(os.path.join(PATH, "config")) if file_name.endswith(".json")]
    
    data_list = []
    
    for file_name in config_file_list:
        
        file_path = os.path.join(PATH, "config", file_name)
        try:
            with open(file_path, "r", encoding="utf-8") as fp:
                if file_name=="Node.json":
                    data_node = json.load(fp)
                else:
                    data_multi = json.load(fp)
                    data_list.append(data_multi)
                fp.close()
        except FileNotFoundError:
            print(f"File not found: {file_path}")
        except json.JSONDecodeError:
            print(f"Error decoding JSON in file: {file_path}")
        except Exception as e:
            print(f"An unexpected error occurred while reading {file_path}: {e}")
    
    # print(data_list)
    return data_list,data_node 

